# -*- coding:utf-8 -*-
"""
@Author : 审心
@Time : 2023/5/27 14:18
"""
from dataclasses import dataclass
from enum import Enum

from enum import Enum
from typing import Optional


class Comparison(Enum):
    """
    比较符号枚举
    """
    EQ: str = "=="
    NE: str = "!="
    LT: str = "<"
    GT: str = ">"
    LE: str = "<="
    GE: str = ">="
    V_Include_STR_LIST = ""


@dataclass
class FastCompare:
    """
    快速构建值比较对象
    l_v 左侧参数
    r_v 右侧参数
    op: 条件符号
    """
    op: Optional[str]
    l_v: Optional[any] = None
    r_v: Optional[any] = None

    def __call__(self):
        if self.op == Comparison.EQ:
            return self.l_v == self.r_v
        elif self.op == Comparison.NE:
            return self.l_v != self.r_v
        elif self.op == Comparison.LT:
            return self.l_v < self.r_v
        elif self.op == Comparison.GT:
            return self.l_v > self.r_v
        elif self.op == Comparison.LE:
            return self.l_v <= self.r_v
        elif self.op == Comparison.GE:
            return self.l_v >= self.r_v
        else:
            raise RuntimeError(f"暂不支持的比较符号 : {self.op}")

    def set_l_v(self, v: any):
        self.l_v = v
        return self

    def set_r_v(self, v: any):
        self.r_v = v
        return self

    def set_op(self, op: str):
        self.op = op
        return self
